<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <base href="${initParam.domain}">
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!-- Bootstrap -->
    <link href="static/css/bootstrap.min.css" rel="stylesheet">
    <title>编辑文章</title>
</head>
<body>
    <div class="container">
    <h1>撰写文章</h1>
    <form:form modelAttribute="article" action="article/publish" method="post">
        <p class="form-group">
            <label>作者</label>
            <form:select path="author.id" disabled="${article.id>0?true:false}" class="form-control">
                <form:option value="0" label="--- Select ---"/>
                <form:options items="${authors}" itemLabel="nickname" itemValue="id" />
            </form:select>
        </p>
        <div class="form-group">
            <label>标题</label>
            <div class="form-inline">
            <form:select path="status" class="form-control">
                <option value="0">请选择</option>
                <option value="1"<c:if test="${article.status eq '1'}"> selected="selected"</c:if>>正常</option>
                <option value="2"<c:if test="${article.status eq '2'}"> selected="selected"</c:if>>锁定</option>
                <option value="3"<c:if test="${article.status eq '3'}"> selected="selected"</c:if>>异常</option>
                <option value="4"<c:if test="${article.status eq '4'}"> selected="selected"</c:if>>冰封</option>
            </form:select>
            <form:input path="title" size="auto" class="form-control" />
            </div>
        </div>
        <p class="form-group">
            <label>概述</label>
            <form:textarea path="description" rows="5" cols="50" class="form-control"></form:textarea>
        </p>
        <p class="form-group">
            <label>内容</label>
            <form:textarea path="content" rows="5" cols="50" class="form-control"></form:textarea>
        </p>
        <div class="form-group">
            <label>可见性</label>
            <div>
            <form:checkboxes items="${roleList}" path="roles" itemLabel="descrip" itemValue="symbol"/>
            </div>
        </div>
        <!-- 
        <div class="form-group">
            <label>参考文章</label>
            <a class="btn btn-default" href="#" role="button" data-target="#myModal" data-toggle="modal">添加</a>
            <div id="a">
                <p>
                    <input type="checkbox" name="pid" value="1" />
                    <input type="text" name="anchor_1" value="" />
                    <input type="url" name="url_1" value="" />
                </p>
                <p>
                    <input type="checkbox" name="pid" value="2" />
                    <input type="text" name="anchor_2" value="" />
                    <input type="url" name="url_2" value="" />
                </p>
                <p>
                    <input type="checkbox" name="pid" value="3" />
                    <input type="text" name="anchor_3" value="" />
                    <input type="url" name="url_3" value="" />
                </p>
            </div>
        </div>-->
        <form:hidden path="id"/>
        
       <button type="submit" class="btn btn-default">提交 </button>
    </form:form>
    </div>
<!-- Modal -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
        <h4 class="modal-title" id="myModalLabel">添加文章引用</h4>
      </div>
      <div class="modal-body">
        <div class="form-group">
            <label>连接</label>
            <input type="url" size="10" name="url" class="form-control"/>
        </div>
        <div class="form-group">
            <label>锚点</label>
            <input type="text" size="10" name="anchor" class="form-control"/>
        </div>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
        <button type="button" class="btn btn-primary">Save changes</button>
      </div>
    </div>
  </div>
</div>
    <!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
    <script src="static/js/jquery.min.js"></script>
    <!-- Include all compiled plugins (below), or include individual files as needed -->
    <script src="static/js/bootstrap.min.js"></script>
    <script type="text/javascript">
    jQuery(function($){
        $('#myModal').find('.btn-primary').click(function(e){
            var button=$(e.relatedTarget);
            var anchor=$('#myModal').find('input[name=anchor]').val();
            var ancurl=$('#myModal').find('input[name=url]').val();
            console.log('<a href="'+ancurl+'">'+anchor+'</a>');
        });
    });
    </script>
</body>
</html>